<?php
/**
 * @description: a simple page builder
 * Date: 15-8-28
 * @author sunnyw<iwisunny@gmail.com>
 */
class PageBuilder
{
    private $_ci;

    function __construct()
    {
        $this->_ci=&get_instance();
    }

    function side_menu()
    {
        //parse side menu conf data
        $this->_ci->config->load('side_menu');
        $nav_tree = $this->_ci->config->item('side_menu');

        //render menu tree
        //导航html
        $nav_cont = '';
        //用户权限数组
        if(is_array($nav_tree) && !empty($nav_tree)) {
            foreach($nav_tree as $module_name => $module_conf) {
                $sub = $module_conf['sub'];
                $label = $module_conf['label'];
                $icon = isset($module_conf['icon'])?$module_conf['icon'] : 'fa-folder';
                if(is_array($sub)) {
                    $nav_cont .= <<<EOT
                    <li>
                        <a href="#" class="menu-dropdown">
                            <i class="menu-icon fa {$icon}"></i>
                            <span class="menu-text"> {$label} </span>
                            <i class="menu-expand"></i>
                        </a>
                        <ul class="submenu">
EOT;

                    foreach($sub as $key => $item) {
                        $item_link = $item['url'];
                        $nav_cont .= <<<EOT
                            <li>
                                 <a href="{$item_link}">
                                    <span class="menu-text"> {$item['name']} </span>
                                </a>
                            </li>
EOT;

                    }
                    $nav_cont .= '</ul></li>';
                }

            }
        }

        return $nav_cont;

    }
}